<?php

require_once "provider.php";
require_once dirname(__FILE__)."/../common/utility.php";

class Netfonds extends Provider{
	public function __construct($rank = 0, $map = NULL){
		parent::__construct(get_class(), Provider::$TYPE_SINGLETICK, $map, $rank);
	}
	
	protected function CreateMap(){
		$this->map = new Map("time", "quantity", "price");
	}
	
	public function Query($ticker, $ts){
		/*
		 * es. di risultato di query:
		 * 
		 *	time,price,quantity,board,source,buyer,seller,initiator
			20150203T153000,118.5,2600,,Auto trade,,,
			20150203T153000,118.38,100,,Auto trade,,,
			20150203T153000,118.23,100,,Auto trade,,,
			20150203T153000,118.27,395325,,Auto trade,,,
			20150203T153000,118.37,100,,Auto trade,,,
			20150203T153000,118.38,100,,Auto trade,,,
			20150203T153000,118.39,100,,Auto trade,,,
			20150203T153000,118.26,100,,Auto trade,,,
			20150203T153000,118.235,100,,Auto trade,,,
		 */
		
		$strTs = date("Ymd", $ts);
		$strQ = "http://hopey.netfonds.no/tradedump.php?date=".$strTs."&paper=".$ticker."&csv_format=csv";
// 		$array = array_map('str_getcsv', file($strQ));
// 		$header = array_shift($array);
// 		array_walk($array, '_combine_array', $header);

		$array = array();
		csv2assocArray($array, $strQ);
		
		return new ProviderQuery($array);
	}
}

?>